package com.example.rotateimageview.previewImageDemo

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import cn.neoclub.uki.commons.layout.*
import com.bumptech.glide.Glide
import com.example.rotateimageview.R
import com.example.rotateimageview.flutter.BaseFlutterActivity
import io.flutter.embedding.android.FlutterFragment
import io.flutter.embedding.android.FlutterView
import io.flutter.embedding.android.RenderMode
import kotlinx.android.synthetic.main.activity_preview_list_layout.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class PreviewListActivity : BaseFlutterActivity(), View.OnClickListener {
    private val TAG_FLUTTER_FRAGMENT = "flutter_fragment"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_preview_list_layout)
        flutterFragment = supportFragmentManager.findFragmentByTag(TAG_FLUTTER_FRAGMENT) as? FlutterFragment

        if (flutterFragment == null) {
//            flutterFragment = FlutterFragment.createDefault()
            flutterFragment = FlutterFragment
                .withCachedEngine("my_engine_id")
                .renderMode(RenderMode.texture)
                .shouldAttachEngineToActivity(true)
                .build()
            supportFragmentManager.beginTransaction()
                .add(R.id.fragment,flutterFragment!!,TAG_FLUTTER_FRAGMENT)
                .commit()
        }

        CoroutineScope(Dispatchers.Default).launch {
           val a =  delayA()
        }
    }
    suspend fun delayA():Int {
        delay(3000)
        return  1
    }

    override fun onClick(v: View?) {

    }

    override fun onDestroy() {
        super.onDestroy()
    }
}